package com.basic.bio.chat.groupchat;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Description:
 * @Date: 2024-03-28 19:39
 * @Author: wz
 **/
public class ServerSendThread extends Thread{

    private Socket socket;

    public ServerSendThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        System.out.println("服务端开始发消息咯。。。");
        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
            while (sc.hasNextLine()){
                for (Socket s : Server.socketList) {
                    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
                    writer.write(sc.nextLine());
                    writer.newLine();
                    writer.flush();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            sc.close();
        }
    }
}
